<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
	<% String path=request.getContextPath(); String basePath=request.getScheme() + "://" + request.getServerName() + ":"
		+ request.getServerPort() + path + "/" ; %>

		<!DOCTYPE html>
		<html>

		<head>
			<base href="<%=basePath%>">

			<title>交货单</title>

			<meta http-equiv="pragma" content="no-cache">
			<meta http-equiv="cache-control" content="no-cache">
			<meta http-equiv="expires" content="0">
			<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
			<meta http-equiv="description" content="This is my page">
			<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

		</head>

		<body>
			<%@ include file="/WEB-INF/jsp/common/headerSupply.jsp" %>
				<%@ include file="/WEB-INF/jsp/common/loadDiv.jsp" %>

					<script type="text/javascript">
						$(function () {
							$('#startTime').datebox('setValue', getBeforeCurrentDate30Days());
							$('#endTime').datebox('setValue', getNowFormatDate());
							bindgrid();
						});
					</script>
					<script>
						function del(node) {
							$.ajax({
								type: "delete",
								url: 'purchase/receive/good/delete?' + 'godId=' + godId,
								//                dataType: "xml",				
								success: function (data) {
									$.messager.alert('消息', data.msg);
									$('#add').window('close');
									bindgrid();
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							});
						}

						function save() {
							if (!$('#fm').form('validate')) {
								return;
							}
							var model = {
								godId: $('#godId').textbox('getValue'),
								mmId: $('#mmId').textbox('getValue'),
								godCode: $('#godCode').textbox('getValue'),
								infCode: $('#infCode').textbox('getValue'),
								infName: $('#infName').textbox('getValue'),
								ordCode: $('#ordCode').textbox('getValue'),
								mmCode: $('#mmCode').textbox('getValue'),
								mmDetail: $('#mmDetail').textbox('getValue'),
								planNum: $('#planNum').textbox('getValue'),
								mmUnit: $('#mmUnit').textbox('getValue'),
								mmUnitDetail: $('#mmUnitDetail').textbox('getValue'),
								godIsWeight: $('#godIsWeight').textbox('getValue'),
								godPlanDate: $('#godPlanDate').textbox('getValue'),
								godRealDate: $('#godRealDate').textbox('getValue'),
								godBillNum: $('#godBillNum').textbox('getValue'),
								godRowNum: $('#godRowNum').textbox('getValue'),
								godChildRow: $('#godChildRow').textbox('getValue'),
								godCar: $('#godCar').textbox('getValue'),
								godOldNum: $('#godOldNum').textbox('getValue'),
								godNewNum: $('#godNewNum').textbox('getValue'),
								godTax: $('#godTax').textbox('getValue'),
								createTime: $('#createTime').textbox('getValue'),
								createName: $('#createName').textbox('getValue'),
								createId: $('#createId').textbox('getValue'),
								updateId: $('#updateId').textbox('getValue'),
								updateName: $('#updateName').textbox('getValue'),
								updateTime: $('#updateTime').textbox('getValue'),
								delFlag: $('#delFlag').textbox('getValue'),
								status: $('#status').textbox('getValue'),
								remark: $('#remark').textbox('getValue')
							};
							$.ajax({
								type: "post",
								dataType: "json",
								url: 'purchase/receive/good/save',
								data: JSON.stringify(model),
								contentType: "application/json",
								success: function (data) {
									if (data.code != 60200) {
										$.messager.alert('消息', data.msg);
									} else {
										$.messager.alert('消息', data.msg);
										let dg = $('#dg');
										dg.datagrid('enableFilter');
										dg.datagrid('load');
										$('#add').window('close');
									}
								},
								error: function (XMLHttpRequest, textStatus, errorThrown) {
									$.messager.alert('消息', errorThrown);
								}
							})

						}

						function editrow() {
							//编辑用户
							var row = $('#dg').datagrid('getSelected');
							if (row) {
								$('#add').window('open');
								$('#fm').form('load', row);

							} else {
								$.messager.alert('消息', '请选中一条数据');
							}
						}
					</script>
					<script>
						/**
						 *  按条件查询报价列表
						 */
						function selectList() {
							var startTime = $('#startTime').datebox('getValue')
							var endTime = $('#endTime').datebox('getValue')
							var status = $('#status').combobox('getValue');
							var dg = $('#dg');
							dg.datagrid('enableFilter');
							dg.datagrid('load', {
								startTime: startTime ? startTime : '',
								endTime: endTime ? endTime : '',
								status: status ? status : ''
							});
						}

						function bindgrid() {
							var startTime = $('#startTime').datebox('getValue')
							var endTime = $('#endTime').datebox('getValue')
							var status = $('#status').combobox('getValue');
							$('#dg').datagrid({
								title: '交货单列表',
								queryParams: {
									startTime: startTime,
									endTime: endTime,
									status: status
								},
								url: "supply/receive/good/selectList",
								iconCls: 'icon-application',
								width: getWidth(0.98),
								height: 415,
								nowrap: true,
								rownumbers: true,
								animate: false,
								collapsible: false,
								clientPaging: false,
								remoteFilter: true,
								singleSelect: true,
								pagination: true,
								remoteSort: true,
								frozenColumns: [[{
									field: 'godId',
									title: '交货单id',
									sortable: true,
									hidden: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'mmId',
									title: '物料id',
									sortable: true,
									hidden: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godCode',
									title: '交货单号',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								},]],
								columns: [[{
									field: 'ordCode',
									title: '订单编号',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godCompanyCode',
									title: '公司代码',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godCompanyName',
									title: '公司名称',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godCreateDate',
									title: '创建日期',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'mmCode',
									title: '物料号码',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'mmDetail',
									title: '物料描述',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'planNum',
									title: '需求总数量',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'mmUnit',
									title: '计量单位',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'mmUnitDetail',
									title: '计量单位描述',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godIsWeight',
									title: '是否过磅',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godPlanDate',
									title: '计划交货日期',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godRealDate',
									title: '实际交货日期',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godBillNum',
									title: '开票数量',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godMoney',
									title: '开票金额',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godRowNum',
									title: '行项目号',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godChildRow',
									title: '次行项目号',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godCar',
									title: '车牌号码',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godOldNum',
									title: '原发数量',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godNewNum',
									title: '实收数量',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'godTax',
									title: '税率',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}, {
									field: 'status',
									title: 'status',
									sortable: true,
									formatter: function (val, rec) {
										let status = val ? val : '';
										return unescape(status == '0' ? '待开票' : '已开票');
									}
								}, {
									field: 'remark',
									title: 'remark',
									sortable: true,
									formatter: function (val, rec) {
										return val ? unescape(val) : '';
									}
								}]],
								toolbar: [],
								onLoadSuccess: function () {
								},
								onDblClickRow: function () {
									// 									editrow();
								}
							});
							$('#dg').datagrid('enableFilter');
						}

						// 导出采购计划列表
						function exportList() {
							let startTime = $('#startTime').datebox('getValue')
							let endTime = $('#endTime').datebox('getValue')
							let status = $('#status').combobox('getValue')

							var form = [];
							form.push('startTime=' + (startTime ? startTime : ''));
							form.push('endTime=' + (endTime ? endTime : ''));
							form.push('status=' + (status ? status : ''));
							console.log('form:', form)
							let url = 'api/supply/receive/good/export'
							let xhr = new XMLHttpRequest()
							xhr.open('POST', url, true)
							xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
							xhr.setRequestHeader('token', localStorage.getItem('tokenSupply'));
							xhr.setRequestHeader('userType', localStorage.getItem('userType'));
							xhr.responseType = 'blob'
							xhr.onload = function () {
								if (this.status == 200) {
									let blob = this.response
									let reader = new FileReader()
									reader.readAsDataURL(blob)
									reader.onload = function (e) {
										let a = document.createElement('a')
										a.download = '采购交货单' + new Date().toLocaleDateString() + '-' + new Date().toLocaleTimeString() + '.xlsx'
										a.href = e.target.result
										$('body').append(a)
										a.click()
										$(a).remove()
									}
								}
							}
							xhr.send(form.join('&'))
						}
					</script>
					<style scoped="scoped">
						.textbox {
							height: 20px;
							margin: 0;
							padding: 0 2px;
							box-sizing: content-box;
						}

						/*.table tr {
        height: 15px;
    }*/
					</style>
					<div class="query_criteria" id="query_criteria">
						<div style="margin: 5px 0px">
							<%-- 搜索框 --%>
								<label style="font-size: 12px;">创建时间：</label> <input class="easyui-datebox"
									name="startTime" id="startTime"
									data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
									value="" style="width: 150px"> <label style="font-size: 10px;">~</label> <input
									class="easyui-datebox" name="endTime" id="endTime"
									data-options="required:true,showSeconds:false,formatter:myformatter,parser:myparser"
									style="width: 150px" /> <label
									style="margin-left: 20px; font-size: 12px;">状态：</label> <input
									class="easyui-combobox" id="status" name="status" style="width: 80px;" data-options="valueField: 'value',editable:false,
						textField: 'label',panelHeight:'auto',data: [{
							label: '全部',
							value: ''
						},{
							label: '待开票',
							value: '0',
							selected:true
						},{
							label: '已开票',
							value: '1'
						}]">
								</select> <a id="search" style="margin-left: 30px" href="javascript:void(0)"
									class="easyui-linkbutton" data-options="iconCls:'icon-search'"
									onclick="selectList()">查询</a><a id="export" style="margin-left: 10px"
									href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-export'" onclick="exportList()">导出</a>
						</div>

						<table id="dg"></table>

						<div id="add" class="easyui-window" closed="true" modal="true" title="用户信息"
							style="width: 500px; height: 450px; padding: 10px 20px">
							<form id="fm" class="ssec-form">
								<table class="table">
									<tr>
										<td>
											<div class="ssec-label">交货单id：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godId" name="godId" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">物料id：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="mmId" name="mmId" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">交货单号：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godCode" name="godCode" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">供应商编号：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="infCode" name="infCode" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">供应商名称：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="infName" name="infName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">订单编号：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="ordCode" name="ordCode" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">物料号码：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="mmCode" name="mmCode" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">物料描述：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="mmDetail" name="mmDetail" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">需求总数量：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="planNum" name="planNum" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">计量单位：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="mmUnit" name="mmUnit" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">计量单位描述：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="mmUnitDetail" name="mmUnitDetail" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">是否过磅：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godIsWeight" name="godIsWeight" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">计划交货日期：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godPlanDate" name="godPlanDate" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">实际交货日期：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godRealDate" name="godRealDate" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">开票数量：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godBillNum" name="godBillNum" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">行项目号：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godRowNum" name="godRowNum" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">次行项目号：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godChildRow" name="godChildRow" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">车牌号码：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godCar" name="godCar" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">原发数量：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godOldNum" name="godOldNum" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">实收数量：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godNewNum" name="godNewNum" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">税率：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="godTax" name="godTax" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">create_time：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="createTime" name="createTime" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">create_name：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="createName" name="createName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">create_id：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="createId" name="createId" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">update_id：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="updateId" name="updateId" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">update_name：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="updateName" name="updateName" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">update_time：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="updateTime" name="updateTime" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">del_flag：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="delFlag" name="delFlag" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">status：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="status" name="status" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
									<tr>
										<td>
											<div class="ssec-label">remark：</div>
										</td>
										<td>
											<div class="ssec-text normal">
												<input id="remark" name="remark" class="easyui-textbox"
													data-options="required:true" />
											</div>
										</td>
									</tr>
								</table>
								<div style="padding: 5px; text-align: right;">
									<a class="easyui-linkbutton" onclick="save();" iconcls="icon-save">保存</a>
								</div>
							</form>
						</div>
					</div>
		</body>

		</html>